package com.yand.DesignPattern.Singleton;

public class Singleton {
    public static final int SUCCESS_HEAD = 0;
    private static  Singleton singleton = null;
    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

    private Singleton(){

    }


    /**
     * 多线程模式下的单例模式
     * @return
     */
    public  static  Singleton getIntance1(){

        if(singleton == null){

            /**
             * 多线程下的单例模式的实现
             */
            synchronized (Singleton.class){
               if(singleton == null){
                   singleton = new Singleton();
               }


            }

        }
        return singleton;
    }


    /**
     * 单线程下的单例模式
     * @return
     */
    public static Singleton getIntance2(){

        if(singleton == null){
            singleton = new Singleton();
        }

        return singleton;
    }


    /**
     * 采取内部类的实现单例
     * @return
     */
    public static Singleton getIntance3(){


        return SingletonFactory.instance;
    }


    /**
     * 内部类的静态方法实现
     */
     static class SingletonFactory{

        private static Singleton instance = new Singleton();



    }












}
